package ordinaryArray;

/*
 *@description 删除有序数组中的重复项 II
 *@author hkfan
 *@version 1.0
 *@create 2025/5/19 17:00
 */
public class LeetCode_80 {

    public int removeDuplicates(int[] nums) {
        //1. 定义变量
        int i = 0 , j = 0;
        //2. 循环标记
        while (i< nums.length && j< nums.length){
            int temp = j;
            while (j< nums.length && nums[temp]==nums[j] ){
                j++;
            }
            if (j-temp>2){
                for (int k = temp+2; k < j; k++) {
                    nums[k]= nums[0]-1;
                }
            }
            i=j;
        }
        //3. 重新定义
        i = 0 ;
        j = 0;
        //4. 清除已被标记的值
        while (i< nums.length && j< nums.length){
            while (j< nums.length &&nums[j]==nums[0]-1){
                j++;
            }
            if(j< nums.length){
                nums[i]=nums[j];
                i++;j++;
            }

        }
        return i;
    }

}
